page.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { CashbackTypes } from "@/api/cashback";
  2. import { UserInfoRep, UserVipInfo } from "@/api/user";
  3. import { getMoneyApi } from "@/api/userWallt";
  4. import { server } from "@/utils/server";
  5. import ItemCom from "./component/ItemCom";
  6. import ModalCom from "./component/ModalCom";
  7. import "./page.scss";
  8. import { ProfileHeader } from "./ProfileHeader";
  9. const getUserInfo = async () => {
  10. return server
  11. .request<UserInfoRep>({
  12. url: "/v1/api/user/user_info",
  13. method: "POST",
  14. next: { revalidate: 0 },
  15. })
  16. .then((res) => {
  17. if (res.code === 200) return res.data;
  18. return {};
  19. });
  20. };
  21. /**
  22. * @description 前台用户VIP信息 接口地址:https://app.apifox.com/link/project/4790544/apis/api-201160713
  23. */
  24. const getVipApi = async () => {
  25. return server
  26. .request<UserVipInfo>({
  27. url: "/v1/api/user/user_vip_info",
  28. method: "POST",
  29. cache: "no-cache",
  30. })
  31. .then((res) => {
  32. if (res.code === 200) return res.data;
  33. });
  34. };
  35. const getCashBackApi = async () => {
  36. return server
  37. .request<CashbackTypes>({
  38. url: "/v1/api/front/activity_cash",
  39. method: "post",
  40. })
  41. .then((res) => {
  42. return res.data;
  43. })
  44. .catch((error) => {
  45. return {
  46. rules: [],
  47. last_period: { end_time: 0, start_time: 0 },
  48. next_period: {
  49. end_time: 0,
  50. start_time: 0,
  51. },
  52. amount: 0,
  53. bet: 0,
  54. status: "expired",
  55. };
  56. });
  57. };
  58. export const dynamic = "force-dynamic";
  59. export const revalidate = 0;
  60. const Profile = async () => {
  61. const userInfo = await getUserInfo();
  62. const userMoney = await getMoneyApi();
  63. const userVip = await getVipApi();
  64. const cashback = await getCashBackApi();
  65. const max = cashback.rules.reduce(
  66. (acc, item) => (acc > item.cashback ? acc : item.cashback),
  67. 0
  68. );
  69. return (
  70. <div className="profile-box">
  71. <ProfileHeader userInfo={userInfo} userMoney={userMoney} userVip={userVip!} />
  72. <ItemCom max={max} />
  73. <ModalCom />
  74. </div>
  75. );
  76. };
  77. export default Profile;